package com.mvd.app.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mvd.app.R;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.model.An_Huan_Model;

import java.util.List;

/**
 * @Title: 待检测车辆列表adapter
 */
public class CarsInforListAdapter2 extends BaseAdapter {
    Context context;
    LayoutInflater inflater;
    private List<An_Huan_Model> data;
    String MODE;

    public CarsInforListAdapter2(Context context, List<An_Huan_Model> data, String MODE) {
        super();
        this.context = context;
        this.data = data;
        this.MODE = MODE;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        int l = 0;
        if (data != null && data.size() > 0) {
            l = data.size();
        } else {
            l = 0;
        }
        return l;
    }


    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder_left holder1 = null;
        if (convertView == null) {
            convertView = inflater.inflate(
                    R.layout.holder_consume3, parent, false);
            holder1 = new ViewHolder_left();
            holder1.line = (LinearLayout) convertView
                    .findViewById(R.id.holder_consume_view_diveder3);
            holder1.hold_consume3_llout = (LinearLayout) convertView
                    .findViewById(R.id.hold_consume3_llout);
            holder1.chepai_haoma = (TextView) convertView
                    .findViewById(R.id.hold_consume_chepaihao3);
            holder1.cheliang_leixing = (TextView) convertView
                    .findViewById(R.id.hold_consume_chepaileixing3);
            holder1.jiance_cishu = (TextView) convertView
                    .findViewById(R.id.hold_consume_jiancecishu_my_times3);
            holder1.haoma_1 = (TextView) convertView
                    .findViewById(R.id.hold_consume_chepai_haoma_13);
            holder1.type_1 = (TextView) convertView
                    .findViewById(R.id.hold_consume_chepai_leixing_13);
            holder1.times_1 = (TextView) convertView
                    .findViewById(R.id.hold_consume_times_13);
            holder1.jiance_type = (TextView) convertView
                    .findViewById(R.id.hold_consume_jiancecishu_my_times33);
            holder1.jiance_typeName = (TextView) convertView
                    .findViewById(R.id.hold_consume_times_133);

            convertView.setTag(holder1);
        } else {
            holder1 = (ViewHolder_left) convertView.getTag();
        }

        if (SharedPreferencesUtils.getPhotoClipping(context)) {
            holder1.hold_consume3_llout.setVisibility(View.GONE);
            String type_name = "安检";
            if (data.get(position).getIsAnHuan() == 1) {
//                holder1.jiance_type.setText("环保");
//                type_name = "环保";
//                return convertView;
            } else if (data.get(position).getIsAnHuan() == 0) {
                type_name = "安检";
//                holder1.jiance_type.setText("安检");

                String message = "<font color='#000000'>" + "车牌号码" + "</font>" + "<font color='#FF000A'>" + "(" + type_name + ")" + "</font>";

                holder1.haoma_1.setText(Html.fromHtml(message));
//            holder1.haoma_1.setText("车牌号码"+(type_name));
                if (!TextUtils.isEmpty(data.get(position).getCarNo())) {
                    holder1.chepai_haoma.setText(data.get(position).getCarNo() +
                            data.get(position).getPlateExtra());
                }
                if (!TextUtils.isEmpty(String.valueOf(data.get(position).getTypeName()))) {
                    holder1.cheliang_leixing.setText(String.valueOf(data.get(position).getTypeName()));
                }
//            holder1.haoma_1.setText("车牌号码");
                holder1.type_1.setText("车辆类型");
            }
//                if (data.get(position).getIsAnHuan() == 1) {
////                holder1.jiance_type.setText("环保");
//                type_name="环保";
//
//            }
            else if (data.get(position).getIsAnHuan() == 2) {
                if (MODE.equals("F1")) {
                    type_name = "安检-环保";
//                    holder1.jiance_type.setText("安检-环保");
                } else {
                    type_name = "安检";
//                    holder1.jiance_type.setText("安检");
                }

                String message = "<font color='#000000'>" + "车牌号码" + "</font>" + "<font color='#FF000A'>" + "(" + type_name + ")" + "</font>";

                holder1.haoma_1.setText(Html.fromHtml(message));
//            holder1.haoma_1.setText("车牌号码"+(type_name));
                if (!TextUtils.isEmpty(data.get(position).getCarNo())) {
                    holder1.chepai_haoma.setText(data.get(position).getCarNo() +
                            data.get(position).getPlateExtra());
                }
                if (!TextUtils.isEmpty(String.valueOf(data.get(position).getTypeName()))) {
                    holder1.cheliang_leixing.setText(String.valueOf(data.get(position).getTypeName()));
                }
//            holder1.haoma_1.setText("车牌号码");
                holder1.type_1.setText("车辆类型");
            }
//            String message = "<font color='#000000'>" + "车牌号码" + "</font>" + "<font color='#FF000A'>" + "(" + type_name + ")" + "</font>";
//
//            holder1.haoma_1.setText(Html.fromHtml(message));
////            holder1.haoma_1.setText("车牌号码"+(type_name));
//            if (!TextUtils.isEmpty(data.get(position).getCarNo())) {
//                holder1.chepai_haoma.setText(data.get(position).getCarNo() +
//                        data.get(position).getPlateExtra());
//            }
//            if (!TextUtils.isEmpty(String.valueOf(data.get(position).getTypeName()))) {
//                holder1.cheliang_leixing.setText(String.valueOf(data.get(position).getTypeName()));
//            }
////            holder1.haoma_1.setText("车牌号码");
//            holder1.type_1.setText("车辆类型");
//            holder1.times_1.setText("检测流水");
//            holder1.jiance_typeName.setText("检测类型");


        } else {

            if (data.get(position).getIsAnHuan() == 0) {
                holder1.jiance_type.setText("安检");
                holder1.hold_consume3_llout.setVisibility(View.VISIBLE);
                holder1.haoma_1.setText("车牌号码");
                holder1.type_1.setText("车辆类型");
                holder1.times_1.setText("检测流水");
                holder1.jiance_typeName.setText("检测类型");
                if (!TextUtils.isEmpty(data.get(position).getCarNo())) {
                    holder1.chepai_haoma.setText(data.get(position).getCarNo() +
                            data.get(position).getPlateExtra());
                }
                if (!TextUtils.isEmpty(String.valueOf(data.get(position).getTypeName()))) {
                    holder1.cheliang_leixing.setText(String.valueOf(data.get(position).getTypeName()));
                }
                if (!TextUtils.isEmpty(String.valueOf(data.get(position).getTimes())) && !TextUtils.isEmpty(data.get(position)
                        .getPlateFormSN())) {
                    holder1.jiance_cishu.setText(String.valueOf(data.get(position).getTimes()) + " - " + data.get(position).getPlateFormSN());
                }
            } else if (data.get(position).getIsAnHuan() == 1) {
//                holder1.jiance_type.setText("环保");
//                return convertView;
            } else if (data.get(position).getIsAnHuan() == 2) {
                if (MODE.equals("F1")) {
                    holder1.jiance_type.setText("安检-环保");
                } else {
                    holder1.jiance_type.setText("安检");
                }
                holder1.hold_consume3_llout.setVisibility(View.VISIBLE);
                holder1.haoma_1.setText("车牌号码");
                holder1.type_1.setText("车辆类型");
                holder1.times_1.setText("检测流水");
                holder1.jiance_typeName.setText("检测类型");
                if (!TextUtils.isEmpty(data.get(position).getCarNo())) {
                    holder1.chepai_haoma.setText(data.get(position).getCarNo() +
                            data.get(position).getPlateExtra());
                }
                if (!TextUtils.isEmpty(String.valueOf(data.get(position).getTypeName()))) {
                    holder1.cheliang_leixing.setText(String.valueOf(data.get(position).getTypeName()));
                }
                if (!TextUtils.isEmpty(String.valueOf(data.get(position).getTimes())) && !TextUtils.isEmpty(data.get(position)
                        .getPlateFormSN())) {
                    holder1.jiance_cishu.setText(String.valueOf(data.get(position).getTimes()) + " - " + data.get(position).getPlateFormSN());
                }
            }

        }


        return convertView;
    }

    class ViewHolder_left {
        private TextView chepai_haoma, jiance_type, jiance_typeName;
        private TextView cheliang_leixing;
        private TextView jiance_cishu;
        private LinearLayout line, hold_consume3_llout;
        private TextView haoma_1, type_1, times_1;
    }
}